package com.lianboke.link.ad.activity;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ProgressBar;

import com.lianboke.link.ad.R;
import com.lianboke.link.ad.Views.MyListView;
import com.lianboke.link.ad.VolleyUtils.HttpCallBack;
import com.lianboke.link.ad.VolleyUtils.HttpUtil;
import com.lianboke.link.ad.adapter.OrderTypeAdapter;
import com.lianboke.link.ad.adapter.OrdersUnfinishAdapter;
import com.lianboke.link.ad.app.MyApplication;
import com.lianboke.link.ad.beans.OrderListNewModel;
import com.lianboke.link.ad.common.CommonParams;
import com.lianboke.link.ad.dbmanager.OrderDetailsCacheUtils;
import com.lianboke.link.ad.entry.OrdetTypeTable;
import com.lianboke.link.ad.utils.DateUtil;
import com.lianboke.link.ad.utils.DeviceUtils;
import com.lianboke.link.ad.utils.KLog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;

/**
 * 未完成任务列表
 * Created by admin on 2018/1/5.
 */

public class OrdersUnFinishListActivity extends BaseActivity {

    @BindView(R.id.lv_order_1)
    public MyListView lv_order_1;

    @BindView(R.id.rv_swipe_refresh)
    public SwipeRefreshLayout rv_swipe_refresh;

    @BindView(R.id.loading_progress)
    public ProgressBar loading_progress;

    @BindView(R.id.view_empty)
    public View view_empty;


    private  List<OrdetTypeTable> orderTypeTableData=new ArrayList<OrdetTypeTable>();
    private OrdersUnfinishAdapter ordersUnfinishAdapter;//未完成任务适配器


    //数据库操作订单详情
    private OrderDetailsCacheUtils orderDetailsCacheUtils ;

    private String strCurrentDate = "";//今天日期

    @Override
    public int getContentViewId() {
        return R.layout.activity_orders_unfinish_list;
    }

    @Override
    public void initActivityParams(Bundle savedInstanceState) {
        setTitleBackShow(true);
        setTitleContent("未完成任务列表");

        orderDetailsCacheUtils =new  OrderDetailsCacheUtils(actContext);
        strCurrentDate = DateUtil.getCurDateStr("yyyy-MM-dd");
        //设置数据适配器
        ordersUnfinishAdapter = new OrdersUnfinishAdapter(actContext);
        lv_order_1.setAdapter(ordersUnfinishAdapter);


        //初始化为非刷新状态
        rv_swipe_refresh.setRefreshing(false);
        rv_swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener(){
            @Override
            public void onRefresh() {
                //任务列表刷新
                rv_swipe_refresh.setRefreshing(true);
                getOrdersUnfinishDatas();
            }
        });

        //获取任务列表数据
        showLoadingProgress();
        getOrdersUnfinishDatas();
    }

        /**
         * 显示加载框
         */
    private void showLoadingProgress(){
        if(loading_progress!=null && loading_progress.getVisibility()!= View.VISIBLE){
            loading_progress.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 隐藏家在狂
     */
    private void hideLoadingProgress(){
        if(loading_progress!=null && loading_progress.getVisibility()!=View.GONE){
            loading_progress.setVisibility(View.GONE);
        }
    }
    /**
     * 获取未完成的任务信息
     */
    public void getOrdersUnfinishDatas(){
        orderTypeTableData  = orderDetailsCacheUtils.queryOrdersUnfinishDatas();
        if(orderTypeTableData!=null){
            hideEmptyDatasView();
            ordersUnfinishAdapter.setOrderDatas(orderTypeTableData);
        }else{
            showEmptyDatasView();
        }
        hideLoadingProgress();
    }

    /**
     * 显示空数据view
     */
    public void showEmptyDatasView(){
        if(rv_swipe_refresh!=null){
            rv_swipe_refresh.setVisibility(View.GONE);
        }
        if(view_empty!=null){
            view_empty.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 隐藏空数据view
     */
    public void hideEmptyDatasView(){
        if(rv_swipe_refresh!=null){
            rv_swipe_refresh.setVisibility(View.VISIBLE);
        }
        if(view_empty!=null){
            view_empty.setVisibility(View.GONE);
        }
    }
    @Override
    public void getTimerOrderdMyBroadcastReceiver(String action) {
        KLog.e("----------getTimerOrderdMyBroadcastReceiver-----------:" + action);
        if ("android.myapp.timer.orders.auto.start".equals(action)) {
            //结束本页面
            finish();
        }
    }

}

